package com.xxbb.chapter_3.dome2_takeMoney;

public class CreditCard extends Common{
    //无参数构造
    public CreditCard(){
        super();
    }
    //有参构造
    public CreditCard(double maxOverdraft, String name, double balance) {
        super(maxOverdraft, name, balance);
    }
    //设定透支金额
    public void adjustOverdraft(double max){
        super.setMaxOverdraft(max);
    }
    //有参构造
    public CreditCard(String name){
        super.setName(name);
    }
    //存
    public void deposit(double amount){
        super.setBalance(amount);
        if(super.getBalance()==amount){
            printDeposit(true,amount);
            return;
        }
        printDeposit(false,amount);
    }
    //取
    public boolean withdraw(double amount){
        if(amount<=super.getMaxOverdraft()+super.getBalance()){
            super.setBalance(super.getBalance()-amount);
            printWithdraw(true,amount);
            return true;
        }
        printWithdraw(false,amount);
        return false;
    }
    //打印信息
    public void printInfo(){
        System.out.println("持卡人姓名："+super.getName()+"\t余额为："+super.getBalance());
    }
    public void printWithdraw(boolean re,double amount){
        if (re){
            System.out.println("取出"+amount+"成功！");
            return;
        }
        System.out.println("余额不足，取出"+amount+"失败！");
    }
    public void printDeposit(boolean re,double amount){
        if (re){
            System.out.println("取出"+amount+"成功！");
            return;
        }
        System.out.println("取出"+amount+"失败！");
    }

}
